﻿using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;

namespace Wpf_Test1
{
    public class Class2 : INotifyPropertyChanged
    {

        //获取窗体实例化
        private LoginlibraryDemo loginlibraryDemo;
        public Class2(LoginlibraryDemo loginlibraryDemo)
        {
            this.loginlibraryDemo = loginlibraryDemo;
        }



        //可以让文本狂自动为空数据
        public event PropertyChangedEventHandler PropertyChanged;
        private void RaisePropertyChanged(string propertyname)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
            {
                handler(this, new PropertyChangedEventArgs(propertyname));
            }
        }
        private Class1 Class1a = new Class1();

       
        public string UserName
        {
            get { return Class1a.UserName; }
            set
            {
                Class1a.UserName = value;
                RaisePropertyChanged("UserName");
            }
        }

        public string Password
        {
            get { return Class1a.Password; }
            set
            {
                Class1a.Password = value;
                RaisePropertyChanged("Password");
            }
        }
        /// <summary>
        /// 登录的方法
        /// </summary>
        //属性命令按钮绑定Button
        void Denglu()
        {
            //string username = Account.Text;
            //string pwd = Pwd.Text;

            if (UserName == "123" && Password == "456")
            {
                MessageBox.Show("登录成功");
                //实例化
                Index index = new Index();
                index.Show();
                //想办法把当前打开界面的实例拿到，main
                loginlibraryDemo.Close();
            }
            else
            {
                MessageBox.Show("账号密码错误");
                UserName = "";
                Password = "";

            }

        }
        //命令 等下绑定搭配登录按钮上
        bool CanLoginExcute()
        { return true; }
        public ICommand DengLu
        {
            get
            {
                return new DengluCommond(Denglu, CanLoginExcute);
            }

        }
    }
}
